package com.googlecode.maurersmarbles.drawables;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Paint.Align;

import com.googlecode.maurersmarbles.Card;
import com.googlecode.maurersmarbles.Util;

public class SimpleCardDrawable extends CardDrawable {

	/**
	 * The paint that is used to draw the card background.
	 */
	private static Paint BACKGROUND_PAINT;
	/**
	 * The paint that is used to draw the card.
	 */
	private static Paint PAINT;
	/**
	 * The paint used to draw the selection.
	 */
	private static Paint SELECTED_PAINT;

	/**
	 * Creates a new SimpleCardDrawable.
	 * @param card the card to draw
	 * @param corners the corners of the card
	 */
	public SimpleCardDrawable(Card card, Point[] corners) {
		super(card, corners);
	}

	/**
	 * Creates a new SimpleCardDrawable.
	 * @param card the card to draw
	 * @param corners the corners of the card
	 * @param selected whether or not the card is selected
	 */
	public SimpleCardDrawable(Card card, Point[] corners, boolean selected) {
		super(card, corners, selected);
	}

	@Override
	public void drawCard(Canvas canvas, Card card, Point[] corners,
			boolean selected) {

		canvas.drawRect(corners[0].x, corners[0].y, corners[2].x, corners[2].y,
				BACKGROUND_PAINT);

		Util.drawEmptyPolygon(canvas, corners, PAINT);

		String value = card.getText() + card.getSuit();
		// TODO This assumes a rect
		PAINT.setTextSize((corners[1].x - corners[0].x) / 2);
		int x = (int) (corners[0].x + ((corners[1].x - corners[0].x) / 2.0));
		int y = (int) (corners[0].y + (((corners[2].y - corners[0].y) / 2.0) - ((PAINT
				.descent() + PAINT.ascent()) / 2.0)));
		canvas.drawText(value, x, y, PAINT);

		if (selected) {
			Util.drawEmptyPolygon(canvas, corners, SELECTED_PAINT);
		}

	}

	static {

		BACKGROUND_PAINT = new Paint();
		BACKGROUND_PAINT.setColor(Color.WHITE);

		PAINT = new Paint();
		PAINT.setStrokeWidth(2);
		PAINT.setTextAlign(Align.CENTER);

		SELECTED_PAINT = new Paint();
		SELECTED_PAINT.setColor(Color.YELLOW);
		SELECTED_PAINT.setStrokeWidth(10);

	}

}
